package com.tengju.bff.interfaces.shared;

import lombok.Data;

/**
 * @author chenhang
 * @Date 2021/3/6
 */
@Data
public class RankVO {

    String AMOUNT_TYPE = "RANK";
    String AMOUNT_TITLE = "排名";
    Integer rank;
    Integer lastRank;
    Integer rankDiff;
    RankDiffType type;
    Integer value;

    private RankVO(Integer rank, Integer lastRank) {
        this.rank = rank;
        this.value = rank;
        if (rank == null || rank == 0) {
            return ;
        }
        this.lastRank = lastRank;
        if (lastRank == null || lastRank == 0) {
            this.type = RankDiffType.NEW;
            return;
        }

        int diff = rank - lastRank;
        if (diff == 0) {
            this.type = RankDiffType.SAME;
        } else if (diff > 0) {
            this.type = RankDiffType.DOWN;
        } else {
            this.type = RankDiffType.UP;
        }
        this.rankDiff = Math.abs(rank - lastRank);
    }

    public static RankVO of(Integer rank) {
        return of(rank,null);
    }

    public static RankVO of(Integer rank, Integer lastRank) {
        if (rank == null || rank == 0) {
            return null;
        }
        return new RankVO(rank,lastRank);
    }
}
